#include<bits/stdc++.h>
#define y1 Y1
#define fi first
#define endl "\n"
#define se second
#define PI acos(-1)
#define int long long
#define pb(x) push_back(x)
#define PII pair<int, int>
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define _for(i, a, b) for(int i = a; i <= b; ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int dis[210][210];
int n, m, k, ret;
string s;
void Floyd() {
	for(int k = 1; k <= n; ++ k ) {
		for(int i = 1; i <= n; ++ i ) {
			for(int j = 1; j <= n; ++ j ) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}
}

signed main() {
	IOS;
	cin >> n >> m >> k;
	memset(dis, 0x3f, sizeof dis);
	for(int i = 1; i <= n; ++ i ) {
		dis[i][i] = 0;
	}
	for(int i = 1; i <= m; ++ i ) {
		int x, y, val;
		cin >> x >> y >> val;
		dis[x][y] = min(dis[x][y], val);
	}
	Floyd();
	while(k -- ) {
		int x, y;
		cin >> x >> y;
		if(dis[x][y] >= 0x3f3f3f3f / 2) {
			cout << "impossible" << endl;
		} else {
			cout << dis[x][y] << endl;
		}
		
	}
	
	return 0;
}


